import 'package:flutter/material.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ButtonUtil extends StatelessWidget {

  final String text;
  final double fontSize;
  final double borderRadius;
  final double height;
  final Function onTop;
  final Color? textColor;
  final List<Color>? bgColors;
  final FontWeight? fontWeight;
  final bool showBorder;
  final Color? borderColor;
  final double? padding;
  final bool showAddIcon;
  final Alignment begin;
  final Alignment end;

  ButtonUtil({
    required this.text,
    required this.fontSize,
    required this.borderRadius,
    required this.height,
    required this.onTop,
    this.textColor,
    this.bgColors,
    this.fontWeight,
    this.showBorder = false,
    this.borderColor,
    this.padding,
    this.showAddIcon = false,
    this.begin = Alignment.bottomCenter,
    this.end = Alignment.topCenter
  });

  @override
  Widget build(BuildContext context) {
    return InkWellUtil.shakeProofInkWell(Container(
      alignment: Alignment.center,
      height: height,
      padding: EdgeInsets.symmetric(horizontal: padding ?? 0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(borderRadius),
        border:  Border(
          top: showBorder ? BorderSide(
            color: borderColor ?? bgMainColor,
            width: 1.w
          ) : BorderSide.none,
          bottom: showBorder ? BorderSide(
            color: borderColor ?? bgMainColor,
            width: 1.w
          ) : BorderSide.none,
          left: showBorder ? BorderSide(
            color: borderColor ?? bgMainColor,
            width: 1.w
          ) : BorderSide.none,
          right: showBorder ? BorderSide(
            color: borderColor ?? bgMainColor,
            width: 1.w
          ) : BorderSide.none,
        ),
        gradient: LinearGradient(
          begin: begin,
          end: end,
          colors: bgColors == null ? [
            bgMainColor,
            bgExcessiveColor
          ] : bgColors!
        )
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          showAddIcon ? Container(
            margin: EdgeInsets.only(right: 6.w),
            child: Image.asset(
              'assets/icons/icon_add_address.png',
              width: 12.w,
              height: 12.w,
            ),
          ) : Container(),
          Expanded(child: Text(
            text,
            overflow: TextOverflow.ellipsis,
            textAlign: TextAlign.center,
            style: TextStyle(
              color: textColor == null ? textWhiteColor : textColor,
              fontSize: fontSize,
              fontWeight: fontWeight
            ),
          ))
        ],
      ),
    ), () => onTop());
  }
}